#include <stdio.h>
#include "../sjjg/vector.h"

typedef size_t tType;

tType showData(void* p) {
    return *(tType*)p;
}
void showVector(ms_vector_t* v) {
    size_t size = ms_vector_size(v);
    for (size_t i = 0;i < size;++i) {
        printf("%lu ", showData(ms_vector_at(v, i)));
    }
    printf("\nsize:%lu max_size:%lu\n", size, ms_vector_capacity(v));
}
int getSel() {
    printf("1.push back\n");
    printf("2.insert\n");
    printf("3.resize\n");
    printf("4.reserve\n");
    printf("5.show map\n");
    printf("6.delete\n");
    printf("7.clear\n");
    printf("8.front & back\n");
    printf("9.pop back\n");
    printf("10.sort\n");
    printf("other exit\n");
    printf("select please:");
    int i;
    scanf("%d", &i);
    return i;
}
int getV() {
    int a = rand() % 1000;
    printf("push a value:%d\n", a);
    return a;
}
size_t getWhere(const char* str) {
    unsigned long i = 0;
    printf(str);
    scanf("%lu", &i);
    return i;
}
bool vector_less(void* left, void* right) {
    return showData(left) < showData(right);
}
void data_swap(void* left, void* right) {
    tType tmp = showData(left);
    memcpy(left, right, sizeof(tType));
    memcpy(right, &tmp, sizeof(tType));
}
int main(int args, char* argv[]) {
    char a[10] = "01234567";
    memmove(a + 1, a, strlen(a));
    a[0] = 'a';
    printf("%s\n", a);

    ms_vector_t* v = ms_vector_create(NULL, 16, sizeof(tType), NULL);
    if (v) {
        do
        {
            size_t w = 0;
            int a = 0;
            int sel = getSel();
            switch (sel) {
            case 1:
                a = getV();
                ms_vector_push_back(v, &a);
                break;
            case 2:
                a = getV();
                w = getWhere("enter a pos:");
                ms_vector_insert(v, w, &a);
                break;
            case 3:
                w = getWhere("enter a size:");
                ms_vector_resize(v, w);
                break;
            case 4:
                w = getWhere("enter a reserve size:");
                ms_vector_reserve(v, w);
                break;
            case 5:
                showVector(v);
                break;
            case 6:
                w = getWhere("enter a pos:");
                ms_vector_remove(v, w);
                break;
            case 7:
                ms_vector_clear(v);
                break;
            case 8:
                printf("f&b:%lu %lu\n", showData(ms_vector_front(v)), showData(ms_vector_back(v)));
                break;
            case 9:
                ms_vector_pop_back(v);
                break;
            case 10:
                ms_vector_sort(v,vector_less, data_swap);
                break;
            default:
                goto exit;
            }
        } while (1);
exit:
        ms_vector_destory(v);
    }
    return 0;
}
